﻿Public Class CalcularHorasExtras 
    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            Modificar.Enabled = True
            Eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub
    Private Sub CalculosHorasExtrasBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles CalculosHorasExtrasBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.CalculosHorasExtrasBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub CalcularHorasExtras_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.horastipo' table. You can move, or remove it, as needed.
        Me.HorastipoTableAdapter.Fill(Me.DbFireAndIceDataSet.horastipo)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.CalculosHorasExtras' table. You can move, or remove it, as needed.
        Me.CalculosHorasExtrasTableAdapter.Fill(Me.DbFireAndIceDataSet.CalculosHorasExtras)

    End Sub



    Private Sub IdempleadoLookUpEdit_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles IdempleadoLookUpEdit.EditValueChanged
        'TextEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("idempleado")
        TextEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("nombre")
        TextEdit2.EditValue = IdempleadoLookUpEdit.GetColumnValue("apellido")
        TextEdit3.EditValue = IdempleadoLookUpEdit.GetColumnValue("cargo")
        PictureEdit1.EditValue = IdempleadoLookUpEdit.GetColumnValue("fotografia")

    End Sub
    Private Sub CantidadhorasextrasTextEdit_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs)
        If Char.IsLetter(e.KeyChar) Then
            e.Handled = True
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Advertencia", "Solo puede ingresar números")

            CantidadhorasextrasTextEdit.Focus()

        Else


            If Char.IsSeparator(e.KeyChar) Then
                e.Handled = True
                AlertControl1.AppearanceCaption.ForeColor = Color.Red
                AlertControl1.Show(Me, "Advertencia", "No puede ingresar espacios")

                CantidadhorasextrasTextEdit.Focus()

            Else
                e.Handled = False

            End If
        End If
    End Sub

    
    Private Sub IdhoratipoLookUpEdit_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles IdhoratipoLookUpEdit.EditValueChanged
        PorcentajeTextEdit.EditValue = IdhoratipoLookUpEdit.GetColumnValue("valor") + 1

    End Sub

    Private Sub CantidadhorasextrasTextEdit_EditValueChanged_1(sender As System.Object, e As System.EventArgs) Handles CantidadhorasextrasTextEdit.EditValueChanged
        If PorcentajeTextEdit.EditValue = 0 Then
        Else
            TotalbrutoTextEdit.EditValue = Val(CantidadhorasextrasTextEdit.EditValue) * Val(PorcentajeTextEdit.EditValue)
        End If
    End Sub

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

    Private Sub eliminar_Click(sender As System.Object, e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                'DeduccionescategoriaTableAdapter.DeleteDeduccionesCategoriasQuery(IddeduccionescatTextBox.Text)
                'Me.DeduccionescategoriaTableAdapter.Fill(Me.DbFireAndIceDataSet.deduccionescategoria)
                AlertControl1.AppearanceCaption.ForeColor = Color.Green
                AlertControl1.Show(Me, "Advertencia", "Se eliminó satisfactoriamente")

            Catch ex As Exception
                AlertControl1.AppearanceCaption.ForeColor = Color.Red
                AlertControl1.Show(Me, "Error", "No se pudo eliminar el registro")
            End Try

        End If
    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If IdempleadoLookUpEdit.EditValue.Length = 0 Then
            ErrorProvider1.SetError(IdempleadoLookUpEdit, "Debe ingresar un empleado")
            Return
        End If
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)

        If IdhoratipoLookUpEdit.EditValue = 0 Then
            ErrorProvider1.SetError(IdhoratipoLookUpEdit, "Debe ingresar un tipo de hora")
        End If
        ErrorProvider1.SetError(IdhoratipoLookUpEdit, Nothing)
        If CantidadhorasextrasTextEdit.EditValue = 0 Then
            ErrorProvider1.SetError(CantidadhorasextrasTextEdit, "Debe ingresar una cantidad")
        End If
        ErrorProvider1.SetError(CantidadhorasextrasTextEdit, Nothing)

        Try
            CalculosHorasExtrasBindingNavigatorSaveItem.PerformClick()
            AlertControl1.AppearanceCaption.ForeColor = Color.Green
            AlertControl1.Show(Me, "Advertencia", "Se guardó el resgistro satisfactoriamente")
            Mostrar()

        Catch ex As Exception
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "No se pudo guardar el registro")
        End Try
    End Sub

    Private Sub cancelar_Click(sender As System.Object, e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(IdempleadoLookUpEdit, Nothing)
        ErrorProvider1.SetError(IdhoratipoLookUpEdit, Nothing)
        ErrorProvider1.SetError(CantidadhorasextrasTextEdit, Nothing)
        Mostrar()
        Try
            Me.HorastipoTableAdapter.Fill(Me.DbFireAndIceDataSet.horastipo)
        Catch ex As Exception
            AlertControl1.AppearanceCaption.ForeColor = Color.Red
            AlertControl1.Show(Me, "Error", "No puede cancelar")
        End Try
    End Sub

    Private Sub imprimir_Click(sender As System.Object, e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub

    Private Sub GridControl1_Click(sender As System.Object, e As System.EventArgs) Handles GridControl1.Click

    End Sub
End Class